<template>
<view>
<!--pages/search/moredata/moredata.wxml-->
<!--<import src="../../webview/contact.wxml"></import>-->
<!-- <template is="inContact" data="{{showtk}}"/> -->
<!-- 服务 -->
<view class="z-list" v-if="name=='服务'">
  <view v-for="(item, index) in servList" :key="index" @tap="servBtn" :data-path="item.path" :data-appid="item.appid" :data-title="item.title">{{item.title}}</view>
</view>
<!-- 资讯 -->
<view class="z-list" v-if="name=='资讯'">
  <navigator v-for="(item, index) in searchList" :key="index" :url="'../../article/detail/detail?id=' + item.id + '&type=' + item.pagetype + '&city=' + citycode">{{item.title}}</navigator>
</view>
<!-- 办事攻略 -->
<view class="z-list" v-if="name=='指南'">
  <navigator v-for="(item, index) in bsyList" :key="index" :url="'../../article/detail/detail?id=' + item.id + '&type=' + item.pagetype + '&city=' + citycode">{{item.title}}</navigator>
</view>
</view>
</template>

<script>
// pages/search/moredata/moredata.js
//获取应用实例
const app = getApp();
const util = require("../../../utils/util.js");
var page = 1;

export default {
  data() {
    return {
      searchList: [],
      servList: [],
      bsyList: [] // cityname: app.extConfig.cityname,
      // citycode: app.extConfig.citycode,
      ,
      name: "",
      keywords: "",
      citycode: "",
      showtk: false
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      keywords: options.keywords ? decodeURIComponent(options.keywords) : '',
      name: options.name ? decodeURIComponent(options.name) : '',
      citycode: uni.getStorageSync("citycode") ? uni.getStorageSync("citycode") : 'sz'
    });
    uni.setNavigationBarTitle({
      title: decodeURIComponent(this.keywords) + "相关" + decodeURIComponent(this.name)
    });
    util.getUrl(app.globalData.url).then(res => {
      this.getServiceData(this.keywords);
      this.getinfoData(this.keywords, page);
      this.getbsyData(this.keywords, page);
    });
  },

  onShow() {
    page = 0;
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    page++;
    this.getinfoData(this.keywords, page);
    this.getbsyData(this.keywords, page);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  methods: {
    // 获取服务搜索结果
    getServiceData(keywords) {
      let serData = {
        action: "tools",
        city: uni.getStorageSync("city"),
        keywords: keywords,
        type: "search",
        version: app.globalData.version
      };
      util.request('service.php', serData).then(res => {
        this.setData({
          servList: res.data.data
        });
      });
    },

    // 资讯搜索结果
    getinfoData(keywords, page) {
      let searchData = {
        citycode: this.citycode,
        action: 'list',
        pagesize: 20,
        keywords: keywords,
        page,
        version: app.globalData.version
      };
      util.request('index.php', searchData, 'GET').then(res => {
        this.setData({
          searchList: this.searchList.concat(res.data)
        });
      });
    },

    // 办事搜索结果
    getbsyData(keywords, page) {
      let searchData = {
        citycode: this.citycode == "sz" ? "bsy" : this.citycode,
        action: 'list',
        pagesize: 20,
        keywords: keywords,
        bsy: 1,
        page,
        version: app.globalData.version
      };
      util.request('index.php', searchData, 'GET').then(res => {
        this.setData({
          bsyList: this.bsyList.concat(res.data)
        });
      });
    },

    // 工具、服务点击事件
    servBtn(e) {
      let path = e.currentTarget.dataset.path;
      let appid = e.currentTarget.dataset.appid;
      let linkname = e.currentTarget.dataset.title;

      if (path.indexOf("pages") == -1 && path.indexOf("mp.weixin.qq.com") == -1) {
        this.setData({
          showtk: true
        });
        util.navContact(linkname, path);
      } else {
        util.navMethod(path, appid);
      }
    }

  }
};
</script>
<style>
/* pages/search/moredata/moredata.wxss */
.z-list{display: flex;flex-direction: column;margin: 10rpx 30rpx 0 30rpx;}
.z-list navigator{border-bottom: 1rpx solid rgba(232,232,232,1);font-size:28rpx;font-family:PingFang SC;font-weight:500;color:rgba(20,20,20,1);opacity:1;padding: 22rpx 0;}

.z-list view{border-bottom: 1rpx solid rgba(232,232,232,1);font-size:28rpx;font-family:PingFang SC;font-weight:500;color:rgba(20,20,20,1);opacity:1;padding: 22rpx 0;}
</style>